<template>
  <div :style="defaultStyle" :class="isActiveClass">
    <div :style="contentStyle" class="container">
      <div class="header">
        <div class="user-info">
          <el-image :src="userDefaultAvatar" class="avatar"></el-image>
          <div class="user-text">
            <div class="nickname">绿通驾考</div>
            <div class="userid">ID: 1</div>
          </div>
        </div>
        <div class="user-set">
          <img class="icon" src="@/assets/img/user_set.png" />
          <p style="margin-top: -1px">设置</p>
        </div>
      </div>

      <el-scrollbar>
        <div class="vip-scroll">
          <div v-for="(item, index) in vipList" :key="index" class="vip-item">
            <div class="title">{{ item.name }}</div>
            <div class="desc">{{ item.title }}</div>
          </div>
        </div>
      </el-scrollbar>
    </div>
  </div>
</template>

<script setup lang="ts">
  import userDefaultAvatar from '@/assets/img/user_logo.jpg'
  import { useUserStore } from '@/store/modules/user'
  import { vipEquity } from '@/api/userStudentsApi'
  const userStore = useUserStore()
  const userInfo = computed(() => userStore.getUserInfo)

  const props = defineProps({
    contentData: {
      type: Object,
      default() {
        return {}
      }
    },
    pageSetInfo: {
      type: Object,
      default() {
        return {}
      }
    },
    isActiveClass: {
      type: String
    }
  })

  const defaultStyle = computed(() => {
    const s = props.contentData.style
    return {
      paddingTop: s.paddingTop,
      paddingLeft: s.paddingLeft,
      paddingRight: s.paddingRight,
      paddingBottom: s.paddingBottom,
      marginBottom: s.marginBottom
    }
  })

  const contentStyle = computed(() => {
    const s = props.contentData.style
    let obj: Record<string, any> = {}
    if (props.contentData.bgType === 1) {
      obj.backgroundColor = s.backgroundColor
    } else if (props.contentData.bgType === 2) {
      obj.backgroundImage = `url(${s.backgroundImage})`
      obj.backgroundSize = 'cover'
      obj.backgroundRepeat = 'no-repeat'
    }

    if (props.pageSetInfo.navType === 2) {
      obj.paddingTop = '80px'
    }

    return {
      borderRadius: s.borderRadius,
      ...obj
    }
  })

  const vipList = ref<any[]>([])

  async function getVipCardData() {
    const res = await vipEquity({
      pageNum: 1,
      pageSize: 10
    })
    if (res.code === '00000') {
      vipList.value = res.data.list
    }
  }

  onMounted(() => {
    getVipCardData()
  })
</script>

<style scoped lang="scss">
  .container {
    width: 100%;
    padding: 20px 20px 0 20px;
    box-sizing: border-box;
  }

  .header {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .user-info {
    display: flex;
    align-items: center;

    .avatar {
      width: 48px;
      height: 48px;
      border-radius: 50%;
    }
  }

  .user-set {
    display: flex;
    justify-content: center;
    align-items: center;
    background: #fff;
    color: #000;
    border-radius: 15px;
    padding: 6px 12px;
    box-sizing: border-box;

    .icon {
      width: 22px;
      height: 22px;
      margin-right: 6px;
    }
  }

  .user-text {
    display: flex;
    flex-direction: column;
    margin-left: 16px;
  }

  .nickname {
    font-size: 16px;
    font-weight: bold;
    color: #333;
  }

  .userid {
    font-size: 10px;
    color: #888;
  }

  .vip-scroll {
    margin-top: 20px;
    display: flex;
    flex-direction: row;
    padding-bottom: 10px;
  }

  .vip-item {
    flex-shrink: 0;
    width: 130px;
    display: flex;
    flex-direction: column;
    align-items: center;
    background: url('https://image.lutongjiakao.com/system/3c1417462da44e0bb200b5812773f443.png');
    background-size: cover;
    background-repeat: no-repeat;
    background-position: center center;
    border-radius: 12px;
    margin-right: 16px;
    position: relative;
    padding: 10px;
    color: #7d4c07;
    box-sizing: border-box;
  }

  .vip-item .title {
    font-size: 16px;
    font-weight: bold;
  }

  .vip-item .desc {
    font-size: 12px;
  }

  .tag {
    width: 30px;
    //position: absolute;
    //top: -6px;
    //right: 0;
  }

  .active-component {
    border: 1px solid var(--el-color-primary);
  }
</style>
